// 字典map
import store from "@/store";
import type { WddmtDeptField } from "@/typings/businessType";

export type PlayFrequencyKey = keyof typeof dictMap.playFrequency;
export type TypeKey = keyof typeof dictMap.type;

const dictMap = {
  /** 排期播放频次 */
  playFrequency: {
    "1": "每日",
    "3": "每周",
  },
  /** 素材类型 */
  type: {
    "1": "图片",
    "2": "文档",
    "3": "音频",
    "4": "视频",
  },
};

/** 获取字典值 */
const getDictValue = (dicKey: WddmtDeptField, value?: string) => {
  const common = store.getState().common;
  const dict = common.dict[dicKey];
  let ret = "";
  if (dict) {
    const target = dict.find(e => e.value === value);
    console.log("dict: ", target);
    if (target) {
      ret = target.label;
    }
  }
  return ret;
};


const getDmtxxAreaLabel = (val?: string) => getDictValue("m180_area", val);
const getDmtxxFactoryLabel = (val?: string) => getDictValue("m180_factory", val);
const getDmtxxModelLabel = (val?: string) => getDictValue("m180_model", val);
const getDmtxxPlayModeLabel = (val?: string) => getDictValue("m180_play_mode", val);

const getPlayFrequencylabel = (value?: PlayFrequencyKey) => {
  if (value) {
    return dictMap.playFrequency[value];
  } else {
    return "";
  }
};

const getTypeabel = (value?: TypeKey) => {
  if (value) {
    return dictMap.type[value];
  } else {
    return "";
  }
};

export {
  getDmtxxAreaLabel,
  getDmtxxFactoryLabel,
  getDmtxxModelLabel,
  getDmtxxPlayModeLabel,
  getPlayFrequencylabel,
  getTypeabel,
};
